package com.example.IOCtry;

import com.example.IOCtry.config.UserInfo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;

//默认扫描当前类的目录及子目录
@ComponentScan("com.example")
@SpringBootApplication
public class IoCtryApplication {

    public static void main(String[] args) {
        //启动类是帮助我们启动spring,这个命令可以返回一个spring
//        //context上下文，就是spring一个运行环境
      ApplicationContext context=SpringApplication.run(IoCtryApplication.class, args);
//        //从容器中拿对象
//        UserController bean=context.getBean(UserController.class);
//        //如果去掉Control注解，就会报错
//        bean.prin();
//        UserService bean2=context.getBean(UserService.class);
//        bean2.doService();
//        UserService bean3=(UserService) context.getBean("userService");
//        bean3.doService();
//        //根据名称和类型获取bean
//        UserService userService=context.getBean("userService",UserService.class);
//        userService.doService();
        //特殊情况,当类名前两位都是大写，那么bean的名称就是类名，不必遵守小驼峰了就
//        CAr cAr=(CAr) context.getBean("cAr");
//        cAr.ad();
//        UserRepository userRepository=context.getBean(UserRepository.class);
//        userRepository.doRepository();
//        UserComponent userComponent=context.getBean(UserComponent.class);
//        userComponent.doComponent();
//      UserConfig userConfig=context.getBean(UserConfig.class);
//      userConfig.doConfig();
//      System.out.println("userConfig"+userConfig);
//      UserConfig userConfig2=context.getBean(UserConfig.class);
//      userConfig2.doConfig();
//      System.out.println("userConfig2"+userConfig2);
      //@Bean演示
//      UserInfo userInfo=(UserInfo) context.getBean("UserInfo");
//      System.out.println(userInfo);
//      UserInfo userInfo2=(UserInfo) context.getBean("userInfo2");
//      System.out.println(userInfo2);
       UserController userInfo=(UserController) context.getBean(UserController.class);
        userInfo.prin();
    }

}
